const TARGET_SERVICE = "http://10.9.238.234:8050/";
const MOCK_ARRAY = ["oa/login", "sys/getMenus", "oa/logout", "sys/getUserInfo","sys/getCarInfo","sys/getUserCarInfo"];

module.exports = {
  productionSourceMap: false,
  css: {
    loaderOptions: {
      less: {
        javascriptEnabled: true
      }
    }
  },
  devServer: {
    port: 6300,
    proxy: {
      '/clpo': {
        target: TARGET_SERVICE,
        changeOrigin: true,
        bypass: function(req, res) {
          if (req.headers.accept.indexOf("html") !== -1) {
            return "/index.html";
          } else if (process.env.MOCK !== "none") {
            let splits = req.path.split("/clpo/");
            if (splits && splits.length > 0 && splits[1]) {
              if (MOCK_ARRAY.indexOf(splits[1]) !== -1) {
                let mock = require(`./mock/${splits[1]}`);
                let result = mock(req.query);
                //删除缓存，每次修改mock数据后重新调用能够获取到最新的值
                delete require.cache[require.resolve(`./mock/${splits[1]}`)];
                return res.send(result);
              }
            }
            return null;
          }
        }
      }
    }
  }
};
